﻿@model EmailTemplateViewModel
@{
    var returnUrl = ViewData["returnUrl"]?.ToString();
}

<style asp-name="codemirror"></style>
<script asp-name="codemirror" depends-on="admin" at="Foot"></script>
<script asp-name="codemirror-mode-javascript" at="Foot"></script>
<script asp-name="codemirror-addon-display-autorefresh" at="Foot"></script>
<script asp-name="codemirror-addon-mode-simple" at="Foot"></script>
<script asp-name="codemirror-addon-mode-multiplex" at="Foot"></script>
<script asp-name="codemirror-mode-xml" at="Foot"></script>

<script asp-src="~/OrchardCore.Liquid/codemirror/liquid.js" at="Foot"></script>

<h1>@RenderTitleSegments(T["Create Template"])</h1>

<div asp-validation-summary="ModelOnly"></div>
<form asp-action="Create" asp-route-returnUrl="@ViewData["returnUrl"]" method="post">

    <div class="form-group" asp-validation-class-for="Name">
        <label asp-for="Name">@T["Name"]</label>
        <input asp-for="Name" class="form-control" autofocus />
        <span class="text-danger d-block" asp-validation-for="Name"></span>
        <span class="hint">@T["The name of the template."]</span>
    </div>

    <div class="form-group" asp-validation-class-for="Description">
        <label asp-for="Description">@T["Description"]</label>
        <input asp-for="Description" class="form-control" autofocus />
        <span class="hint">@T["The description of the template."]</span>
    </div>


    <div class="form-group" asp-validation-class-for="AuthorExpression">
        <label asp-for="AuthorExpression">@T["From"]</label>
        <textarea asp-for="AuthorExpression" rows="1" class="form-control code"></textarea>
        <span class="text-danger d-block" asp-validation-for="AuthorExpression"></span>
        <span class="hint">@T["The author's email address that defines who the email is from. Leave blank to use the configured email address. With Liquid support."]</span>
    </div>

    <div class="form-group" asp-validation-class-for="SenderExpression">
        <label asp-for="SenderExpression">@T["Sender"]</label>
        <textarea asp-for="SenderExpression" rows="1" class="form-control code"></textarea>
        <span class="text-danger d-block" asp-validation-for="SenderExpression"></span>
        <span class="hint">@T["The sender's email address. Required if not the same than the \"From\" email address. With Liquid support."]</span>
    </div>

    <div class="form-group" asp-validation-class-for="ReplyToExpression">
        <label asp-for="SenderExpression">@T["ReplyTo"]</label>
        <textarea asp-for="ReplyToExpression" rows="1" class="form-control code"></textarea>
        <span class="text-danger d-block" asp-validation-for="ReplyToExpression"></span>
        <span class="hint">@T["The \"reply to\" email address. Required if you want email replies be sent to a different address than the \"From\" address. With Liquid support."]</span>
    </div>

    <div class="form-group" asp-validation-class-for="RecipientsExpression">
        <label asp-for="RecipientsExpression">@T["Recipients"]</label>
        <textarea asp-for="RecipientsExpression" rows="1" class="form-control code"></textarea>
        <span class="text-danger d-block" asp-validation-for="RecipientsExpression"></span>
        <span class="hint">@T["The comma-separated list of recipient email addresses. With Liquid support."]</span>
    </div>

    <div class="form-group" asp-validation-class-for="CCExpression">
        <label asp-for="CCExpression">@T["CC"]</label>
        <textarea asp-for="CCExpression" rows="1" class="form-control code"></textarea>
        <span class="text-danger d-block" asp-validation-for="CCExpression"></span>
        <span class="hint">@T["The comma-separated list of CC recipient email addresses. With Liquid support."]</span>
    </div>

    <div class="form-group" asp-validation-class-for="BCCExpression">
        <label asp-for="BCCExpression">@T["BCC"]</label>
        <textarea asp-for="BCCExpression" rows="1" class="form-control code"></textarea>
        <span class="text-danger d-block" asp-validation-for="BCCExpression"></span>
        <span class="hint">@T["The comma-separated list of BCC recipient email addresses. With Liquid support."]</span>
    </div>

    <div class="form-group" asp-validation-class-for="SubjectExpression">
        <label asp-for="SubjectExpression">@T["Subject"]</label>
        <textarea asp-for="SubjectExpression" rows="1" class="form-control code"></textarea>
        <span class="text-danger d-block" asp-validation-for="SubjectExpression"></span>
        <span class="hint">@T["The subject of the email message. With Liquid support."]</span>
    </div>

    <div class="form-group">
        <label asp-for="Body">@T["Body"]</label>
        <textarea asp-for="Body" rows="5" class="form-control"></textarea>
        <span class="text-danger d-block" asp-validation-for="Body"></span>
        <span class="hint">@T["The body of the email message. With Liquid support."]</span>
    </div>

    <div class="form-group">
        <div class="custom-control custom-checkbox">
            <input type="checkbox" class="custom-control-input" asp-for="IsBodyHtml" />
            <label class="custom-control-label" asp-for="IsBodyHtml">@T["Does the Body contain HTML?"]</label>
            <span class="hint dashed">@T["If checked, indicates the body of the email message is HTML. If unchecked, indicates the body of the email message is plain text."]</span>
        </div>
    </div>



    <div class="form-group">
        <div class="btn-group">
            <button type="submit" name="submit" class="btn btn-primary save">@T["Save"]</button>
            <button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-reference="parent" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <span class="sr-only">@T["Toggle Dropdown"]</span>
            </button>
            <div class="dropdown-menu">
                <button class="dropdown-item save-continue" name="submit" type="submit" value="SaveAndContinue">@T["and continue"]</button>
            </div>
        </div>

        @if (Url.IsLocalUrl(returnUrl))
        {
            <a class="btn btn-secondary cancel" role="button" href="@returnUrl">@T["Cancel"]</a>
        }
    </div>
</form>

<script at="Foot">
    $(function () {
        var codeMirrorOptions = {
            autoRefresh: true,
            lineNumbers: true,
            styleActiveLine: true,
            matchBrackets: true,
            mode: { name: "liquid" },
        };
        CodeMirror.fromTextArea(document.getElementById('@Html.IdFor(x => x.AuthorExpression)'), codeMirrorOptions);
        CodeMirror.fromTextArea(document.getElementById('@Html.IdFor(x => x.SenderExpression)'), codeMirrorOptions);
        CodeMirror.fromTextArea(document.getElementById('@Html.IdFor(x => x.ReplyToExpression)'), codeMirrorOptions);
        CodeMirror.fromTextArea(document.getElementById('@Html.IdFor(x => x.RecipientsExpression)'), codeMirrorOptions);
        CodeMirror.fromTextArea(document.getElementById('@Html.IdFor(x => x.CCExpression)'), codeMirrorOptions);
        CodeMirror.fromTextArea(document.getElementById('@Html.IdFor(x => x.BCCExpression)'), codeMirrorOptions);
        CodeMirror.fromTextArea(document.getElementById('@Html.IdFor(x => x.SubjectExpression)'), codeMirrorOptions);
        CodeMirror.fromTextArea(document.getElementById('@Html.IdFor(x => x.Body)'), codeMirrorOptions);
});
</script>



